﻿using Styx;
using Styx.CommonBot;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FM.Unit
{
    internal static class Unit
    {
        private static LocalPlayer Me { get { return StyxWoW.Me; } }

        public static List<WoWUnit> nearbyUnits(WoWPoint fromLocation, double radius)
        {
            List<WoWUnit> hostile = ObjectManager.GetObjectsOfType<WoWUnit>(true, false);
            var maxDistance2 = radius * radius;
            {
                hostile = hostile.Where(x => !x.IsPlayer && isAttackable(x) && x.Location.Distance2DSqr(fromLocation) < maxDistance2).ToList();
            }
            return hostile;
        }

        public static int countEnemiesInRange(WoWPoint fromLocation, double maxRange)
        {
            return nearbyUnits(fromLocation, maxRange).Count;
        }

        public static bool isAttackable(WoWUnit unit)
        {
            if (unit == null)
                return false;
            if (!unit.CanSelect || !unit.Attackable)
                return false;
            if (unit.IsFriendly)
                return false;
            if (unit.IsDead)
                return false;
            if (isBoss(unit) || isTrainingDummy(unit))
                return true;
            if (unit.IsPet || unit.OwnedByRoot != null)
                return false;
            if (unit.IsNonCombatPet || unit.IsCritter)
                return false;
            if (unit.IsTotem)
                return false;
            return true;
        }

        public static bool isBoss(WoWUnit unit)
        {
            return unit != null && BossList.bossIDs.Contains(unit.Entry);
        }

        internal static bool isTrainingDummy(WoWUnit unit)
        {
            return unit != null && BossList.trainingDummies.Contains(unit.Entry);
        }
    }

    public static class BossList
    {
        public static HashSet<uint> bossIDs
        {
            get
            {
                return _Bosses;
            }
        }

        public static readonly HashSet<uint> _Bosses = new HashSet<uint>
        {
        };

        public static HashSet<uint> trainingDummies
        {
            get
            {
                return _Dummies;
            }
        }

        public static readonly HashSet<uint> _Dummies = new HashSet<uint>
        {
            31146, // Raider's
            54344, // Highlord's Nemesis Trainer (Ebon Hold)
            46647, // 81-85
            32546, // Ebon Knight's (DK)
            31144, // 79-80
            32543, // Veteran's (Eastern Plaguelands)
            32667, // 70
            32542, // 65 EPL
            32666, // 60
            30527, // ?? Boss one (no idea?)
        };
    }
}
